
public class ReturnStmt {
	String rt;
	Expression exp;
	String sm;
	
	public ReturnStmt ( String rt, Expression exp, String sm){
		this.rt = rt;
		this.exp = exp;
		this.sm = sm;
	}
	public String toString(){
		String ret = "ReturnStmt\n";

		String s = "";
		if (exp != null) {
			s +=  exp.toString();
		}

		
		return ret+s;
	}
	public void check() throws SemanticException {
		SymbolTable table = SymbolTable.getInstance();
		if (exp != null) {
			// //System.out.println("test " + exp.cae.ee.ae.me.pe.bl + " " + table.getMethodEntry().type.type);
			// exp.check();
			if (table.getInIf()) {
				table.incrementNumOfReturns();	
			} else {
				// Unconditional return
				table.toggleUnCondIf();
			}
			if (exp.cae.ee.ae.me.pe.nm != null && table.getMethodEntry().type.type != "int"
				&& exp.cae.ee.ae.me.pe.nm != null && table.getMethodEntry().type.type != "float") {
				throw new SemanticException("Wrong type of return");
			} else if (exp.cae.ee.ae.me.pe.st != null && table.getMethodEntry().type.type != "String") {
				throw new SemanticException("Wrong type of return");
			} else if (exp.cae.ee.ae.me.pe.bl != null && table.getMethodEntry().type.type != "boolean") {
				throw new SemanticException("Wrong type of return");
			} else if (exp.cae.ee.ae.me.pe.id != null && table.get(exp.cae.ee.ae.me.pe.id).type.type != table.getMethodEntry().type.type) {
				// //System.out.println("SALEM" + exp.cae.ee.ae.me.pe.id + " " + table.get(exp.cae.ee.ae.me.pe.id).type.type + " " + table.getMethodEntry().type.type);
				throw new SemanticException("Wrong type of return");
			} else {
				exp.check();
			}
		}
	}
}
